

using System;
using System.Collections.Generic;
using System.Text;
using DataAccessLayer;
using EntityLayer;
using DataLayer;
using System.Data;
using InfraStructureLayer;

namespace BusinessLayer
{
	public class busArticleCategories:BusinessBase
	{
		public busArticleCategories() : base()
		{
		}
		#region  Code Factory Generated Methods
		
		
		public DataTable SelectArticleCategories()
		{
			try
			{
				datArticleCategories insDatArticleCategories = new datArticleCategories();
				DbConnector insDbConnector = new DbConnector();
				return insDatArticleCategories.SelectArticleCategories(insDbConnector);
			}
			catch (SFException ex)
			{
				this.ErrorMessage = ex.Message;
			}
			return null;
		}
		public void SelectArticleCategoriesByArticleCategoryId(entArticleCategories parEntArticleCategories)
		{
			try
			{
				datArticleCategories insDatArticleCategories = new datArticleCategories();
				DbConnector insDbConnector = new DbConnector();
				insDatArticleCategories.SelectArticleCategoriesByArticleCategoryId(parEntArticleCategories, insDbConnector);
			}
			catch (SFException ex)
			{
				this.ErrorMessage=ex.Message;
			}
		}
		
		#endregion

        public DataTable SelectArticleCategoriesByLanguageId()
        {
            try
            {
                DbConnector insDbConnector = new DbConnector();
                datArticleCategories insDatArticleCategories = new datArticleCategories();
                return insDatArticleCategories.SelectArticleCategoriesByLanguageId(insDbConnector);
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
            return null;
        }
        public void InsertArticleCategories(entArticleCategories parEntArticleCategories)
        {
            DbConnector insDbConnector = new DbConnector();
            try
            {

                insDbConnector.BeginTransaction();
                datArticleCategories insDatArticleCategories = new datArticleCategories();
                insDatArticleCategories.InsertArticleCategories(parEntArticleCategories, insDbConnector);

                datArticleCategoriesContents insDatArticleCategoriesContents = new datArticleCategoriesContents();
                foreach (entArticleCategoriesContents insEntArticleCategoriesContents in parEntArticleCategories.ArticleCategoriesContentsInsert)
                {
                    insEntArticleCategoriesContents.ArticleCategoryId = parEntArticleCategories.ArticleCategoryId;
                    insDatArticleCategoriesContents.InsertArticleCategoriesContents(insEntArticleCategoriesContents, insDbConnector);
                }
                foreach (entArticleCategoriesContents insEntArticleCategoriesContents in parEntArticleCategories.ArticleCategoriesContentsUpdate)
                {
                    insEntArticleCategoriesContents.ArticleCategoryId = parEntArticleCategories.ArticleCategoryId;
                    insDatArticleCategoriesContents.UpdateArticleCategoriesContentsByArticleCategoriesContentId(insEntArticleCategoriesContents, insDbConnector);
                }
                foreach (entArticleCategoriesContents insEntArticleCategoriesContents in parEntArticleCategories.ArticleCategoriesContentsDelete)
                {
                    insDatArticleCategoriesContents.DeleteArticleCategoriesContentsByArticleCategoriesContentId(insEntArticleCategoriesContents, insDbConnector);
                }
                insDbConnector.CommitTransaction();
            }
            catch (SFException ex)
            {
                insDbConnector.RollbackTransaction();
                this.ErrorMessage = ex.Message;
            }
            catch (Exception ex)
            {
                insDbConnector.RollbackTransaction();
                throw new SFUnHandledException(ex);
            }
        }
        public void UpdateArticleCategoriesByArticleCategoryId(entArticleCategories parEntArticleCategories)
        {

            DbConnector insDbConnector = new DbConnector();
            try
            {

                insDbConnector.BeginTransaction();
                datArticleCategories insDatArticleCategories = new datArticleCategories();
                insDatArticleCategories.UpdateArticleCategoriesByArticleCategoryId(parEntArticleCategories, insDbConnector);

                datArticleCategoriesContents insDatArticleCategoriesContents = new datArticleCategoriesContents();
                foreach (entArticleCategoriesContents insEntArticleCategoriesContents in parEntArticleCategories.ArticleCategoriesContentsInsert)
                {
                    insEntArticleCategoriesContents.ArticleCategoryId = parEntArticleCategories.ArticleCategoryId;
                    insDatArticleCategoriesContents.InsertArticleCategoriesContents(insEntArticleCategoriesContents, insDbConnector);
                }
                foreach (entArticleCategoriesContents insEntArticleCategoriesContents in parEntArticleCategories.ArticleCategoriesContentsUpdate)
                {
                    insEntArticleCategoriesContents.ArticleCategoryId = parEntArticleCategories.ArticleCategoryId;
                    insDatArticleCategoriesContents.UpdateArticleCategoriesContentsByArticleCategoriesContentId(insEntArticleCategoriesContents, insDbConnector);
                }
                foreach (entArticleCategoriesContents insEntArticleCategoriesContents in parEntArticleCategories.ArticleCategoriesContentsDelete)
                {
                    insDatArticleCategoriesContents.DeleteArticleCategoriesContentsByArticleCategoriesContentId(insEntArticleCategoriesContents, insDbConnector);
                }
                insDbConnector.CommitTransaction();
            }
            catch (SFException ex)
            {
                insDbConnector.RollbackTransaction();
                this.ErrorMessage = ex.Message;
            }
            catch (Exception ex)
            {
                insDbConnector.RollbackTransaction();
                throw new SFUnHandledException(ex);
            }
        }
        public void DeleteArticleCategoriesByArticleCategoryId(entArticleCategories parEntArticleCategories)
        {
            DbConnector insDbConnector = new DbConnector();
            try
            {
                insDbConnector.BeginTransaction();

                datArticleArticleCategories insDatArticleArticleCategories = new datArticleArticleCategories();
                entArticleArticleCategories insEntArticleArticleCategories = new entArticleArticleCategories();
                insEntArticleArticleCategories.ArticleCategoryId = parEntArticleCategories.ArticleCategoryId;
                if (insDatArticleArticleCategories.SelectArticleArticleCategoriesByArticleCategoryId(insEntArticleArticleCategories, insDbConnector).Rows.Count > 0)
                {
                    throw new SFBusinessException(GetErrorMessageMultilanguageString(29, new object[] { }));
                }

                datArticleCategoriesContents insDatArticleCategoriesContents = new datArticleCategoriesContents();
                entArticleCategoriesContents insEntArticleCategoriesContents = new entArticleCategoriesContents();
                insEntArticleCategoriesContents.ArticleCategoryId = parEntArticleCategories.ArticleCategoryId;
                insDatArticleCategoriesContents.DeleteArticleCategoriesContentsByArticleCategoryId(insEntArticleCategoriesContents, insDbConnector);


                datArticleCategories insDatArticleCategories = new datArticleCategories();
                insDatArticleCategories.DeleteArticleCategoriesByArticleCategoryId(parEntArticleCategories, insDbConnector);
                insDbConnector.CommitTransaction();
            }
            catch (SFException ex)
            {
                insDbConnector.RollbackTransaction();
                this.ErrorMessage = ex.Message;
            }
            catch (Exception ex)
            {
                insDbConnector.RollbackTransaction();
                throw new SFUnHandledException(ex);
            }
        }
	}
}